package io.lvdaxian.rocketmq.learn.demo.mq.pull.consumer;

import io.lvdaxian.rocketmq.learn.demo.mq.pull.po.User;
import io.lvdaxian.rocketmq.learn.demo.utils.Utils;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 关于 用户 message 消费者
 *
 * @author lihh
 */
@Service
@RocketMQMessageListener(
    topic = "${demo.rocketmq.user.topic}",
    consumerGroup = "${demo.rocketmq.user.consumer.group}",
    // 如果队列中没有数据的话，设置休息的间隔时间
    suspendCurrentQueueTimeMillis = 5000
)
public class UserMessageConsumer implements RocketMQListener<User> {
  
  private static final Logger log = LoggerFactory.getLogger(UserMessageConsumer.class);
  
  @Override
  public void onMessage(User user) {
    log.info("消费的用户信息: {}, 消费时间: {}", user, Utils.getDate());
  }
}
